package com.tcm.portal.web.controller;

import com.base.core.utils.R;
import com.tcm.core.service.AreasService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ucenter/areas")
public class AreasController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private AreasService areasService;

    /**
     * 树形结构
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/tree", produces = MediaType.APPLICATION_JSON_VALUE)
    public R tree() throws Exception{
        return R.success(areasService.listToTree());
    }

    /**
     * 查询某城市下的下级
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/subtree", produces = MediaType.APPLICATION_JSON_VALUE)
    public R treeById(@RequestParam("id") Long id) throws Exception{
        return R.success(areasService.listSubAreas(id));
    }

}
